/**
 * Created by yuzhou on 16/9/23.
 */

define([
    'vue',
    'vuex/mutation-types'
], function(Vue, types) {

    var state = {
        all:[],
        loadTimestamp: -1,
        types: null,
        brands: {},
        goods: {}
    }

    var mutations = {}

    mutations[types.RESET_LOAD_TIME] = function(state) {
        state.loadTimestamp = -1
    }

    mutations[types.RECEIVE_ALL_GOOD] = function(state, all, ts) {
        state.all = all
        state.loadTimestamp = ts
    }

    mutations[types.RECEIVE_GOOD_TYPES] = function(state, goodTypes) {
        state.types = goodTypes
    }

    mutations[types.RECEIVE_GOOD_BRANDS] = function(state, type, goodBrands) {
        Vue.set(state.brands, type, goodBrands)
    }

    mutations[types.RECEIVE_EXT_GOODS] = function(state, brandId, extGoods) {
        Vue.set(state.goods, brandId, extGoods)
    }

    return {
        state: state,
        mutations: mutations
    }
})